import { fileURLToPath, URL } from 'node:url' // 用于指定路径别名
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver({ importStyle: 'sass'})],   // 按需导入组件和样式
    }),
    ElementPlus({
      useSource: true,  // 使用 SCSS 源文件
    }),
  ],

  // 指定@指向src
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },

  // 引入自定义样式文件
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/styles/elplus-reset.scss" as *;`,
      },
    },
  },
})
